package leetcode.editor.cn;

import java.util.Arrays;

public class _75_SortColors {
    public static void main(String[] args) {
        Solution solution = new _75_SortColors().new Solution();
        int[] nums = new int[]{2, 0, 2, 1, 1, 0};
        solution.sortColors(nums);
        System.out.println(Arrays.toString(nums));
    }

    public void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public void sortColors(int[] nums) {
            int n = nums.length;
            int idx = 0;
            for (int i = 0; i < n; i++) {
                if (nums[i] == 0) {
                    swap(nums, i, idx);
                    idx++;
                }
            }
            for (int i = 0; i < n; i++) {
                if (nums[i] == 1) {
                    swap(nums, i, idx);
                    idx++;
                }
            }
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}